import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login/index.vue";
import Layout from "@/views/Layout/index.vue";
import WorkTai from "@/views/workTai/index.vue";
import JiGouGuanli from "@/views/DateJichu/JiGouGuanli.vue";
import JiGouZuoYe from "@/views/DateJichu/JiGouZuoYe.vue";
import YunMonkey from "@/views/DateJichu/YunMonkey.vue";
import Chexing from "@/views/cheAdmin/chexing.vue";
import CheList from "@/views/cheAdmin/cheList.vue";
import Chedengji from "@/views/cheAdmin/chedengji.vue";
import CheXiangqing from "@/views/cheAdmin/components/CheXiangqing.vue";
import KuaiDIEmployee from "@/views/employee/KuaiDIEmployee.vue";
import PaiBan from "@/views/employee/PaiBan.vue";
import SiJiEmployee from "@/views/employee/SiJiEmployee.vue";
import Map from "@/views/employee/components/map.vue";
import SijiXiangqing from "@/views/employee/components/SijiXiangqing.vue";
import Paiban from "@/views/employee/components/Paiban.vue";
import Order from "@/views/business/order.vue";
import YunOrder from "@/views/business/yunOrder.vue";
import OrederXiangqing from "@/views/business/OrederXiangqing.vue";
import YunRenwu from "@/views/dispatch/yunRenwu.vue";
import XianLu from "@/views/dispatch/xianLu.vue";
import QuJianWork from "@/views/dispatch/quJianWork.vue";
import PaiJianWork from "@/views/dispatch/paiJianWork.vue";
import YunXiangqing from "@/views/business/components/yunXiangqing.vue";
import { getToken } from "@/utils/strong";
import NProgress from "nprogress";
const whiterList = ["/login"];
// import OrederXiangqing from "@/views/business/OrederXiangqing.vue";
Vue.use(VueRouter);

const routes = [
  {
    path: "/login",
    component: Login,
  },
  {
    path: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      { path: "dashboard", component: WorkTai },
      { path: "branches/organization-manage", component: JiGouGuanli },
      { path: "branches/institutions-jobs-area", component: JiGouZuoYe },
      { path: "transit/freight-manage", component: YunMonkey },
      { path: "transit/car-models", component: Chexing },
      { path: "transit/vehicle", component: CheList },
      { path: "transit/car-register", component: Chedengji },
      { path: "Xiangqing/:id", component: CheXiangqing },
      { path: "branches/operational-range", component: KuaiDIEmployee },
      { path: "transit/workArrange-manage", component: PaiBan },
      { path: "transit/driver", component: SiJiEmployee },
      { path: "map", component: Map },
      { path: "Siji/:id", component: SijiXiangqing },
      { path: "Paiban", component: Paiban },
      { path: "business/order-manage", component: Order },
      { path: "business/waybill", component: YunOrder },
      { path: "orderXiang/:id", component: OrederXiangqing },
      { path: "transport/transport-task", component: YunRenwu },
      { path: "transport/line-manage", component: XianLu },
      { path: "branches/pickUptask", component: QuJianWork },
      { path: "branches/dispatchTask", component: PaiJianWork },
      { path: "yundanXiangqing/:id", component: YunXiangqing },
    ],
  },
];

const router = new VueRouter({
  routes,
});
router.beforeEach((to, form, next) => {
  // NProgress.start()
  console.log(1);
  const token = getToken();
  if (token) {
    if (to.path === "/login") {
      next("/");
    } else {
      next();
    }
  } else {
    if (whiterList.includes(to.path)) {
      next();
    } else {
      next("/login");
    }
  }
  NProgress.done();
});
router.afterEach(function () {
  console.log(2);
  NProgress.done(); // 关闭进度条
});
export default router;
